package com.junit5.demo;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import entity.ResultList;
import entity.ShellResult;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;

public class Junit5Demo_2_1_DynamicTestDemo {

    @TestFactory
    Collection<DynamicTest> dynamicTest_01() throws IOException {

        List<DynamicTest> dynamicTests=new ArrayList<>();

        ObjectMapper objectMapper=new ObjectMapper(new YAMLFactory());
        ResultList resultList=objectMapper.readValue(new File("src/main/resources/data/shell_test_result.yaml"), ResultList.class);

        for (ShellResult shellResult:resultList.getResultList()) {
            dynamicTests.add(dynamicTest(shellResult.getCaseName(),
                    ()->assertTrue(shellResult.isResult()))
            );
        }

        return dynamicTests;
    }


}
